<template>
	<div>
		<el-dialog title="选择人员" :visible.sync="dialogVisible" width="1000px" @close="resetForm()" padding="0">
			<div>
				<div style="min-height: 450px">
					<UserList v-if="dialogVisible && !radioType" :userId="initialValue.userId" :filterCurrentAccount="filterCurrentAccount" />
					<UserListRadio v-if="dialogVisible && radioType" :userId="initialValue.userId" />
				</div>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="custom" @click="submitForm()" :disabled="radioType && checkedData.hasOwnProperty('userId')">提 交</el-button>
				<el-button @click="dialogVisible = false">取 消</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
import Bus from '@/utils/bus.js';
export default {
	components: {
		UserList: () => import('./UserList.vue'),
		UserListRadio: () => import('./UserListRadio.vue')
	},
	data() {
		return {
			dialogVisible: false,
			checkedData: {
				userId: []
			}
		};
	},
	props: {
		initialValue: {
			type: Object,
			default() {
				return {
					userId: []
				};
			}
		},
		radioType: {
			type: Boolean,
			default: false
		},
		//过滤当前账号 默认不过滤
		filterCurrentAccount: {
			type: Boolean,
			default: false
		}
	},
	watch: {},
	mounted() {
		Bus.$on('userSelect', (v) => {
			this.dialogVisible = true;
		});
		Bus.$on('setGrantUser', (v) => {
			this.checkedData = v;
		});
	},
	beforeDestroy() {
		Bus.$off('userSelect');
		Bus.$off('setGrantUser');
	},
	methods: {
		//提交
		submitForm() {
			this.$emit('e-userData', this.checkedData);
			this.dialogVisible = false;
		},
		//重置表单
		resetForm() {
			this.checkedData = {};
		}
	}
};
</script>
